package com.gitee.xqxyxchy.crypto.impl;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import org.bouncycastle.util.encoders.Base64;

import com.gitee.xqxyxchy.crypto.CryptoParam;
import com.gitee.xqxyxchy.crypto.ICryptoService;

public class Base64Crypto implements ICryptoService {

	private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;

	@Override
	public String encrypt(String originData, CryptoParam... params) {
		byte[] bytes = Base64.encode(originData.getBytes(DEFAULT_CHARSET));
		return new String(bytes, DEFAULT_CHARSET);
	}

	@Override
	public String decrypt(String encryptedData, CryptoParam... params) {
		byte[] bytes = Base64.decode(encryptedData.getBytes(DEFAULT_CHARSET));
		return new String(bytes, DEFAULT_CHARSET);
	}

}
